-
-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New mappers added: LowerCaseMapper
and UpperCaseMapper
#927
New mappers added: LowerCaseMapper
and UpperCaseMapper
#927
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few small changes, after that, ready for merge!
### Available mappers: | ||
|
||
```php | ||
class ContractData extends Data | ||
{ | ||
public function __construct( | ||
#[MapName(CamelCaseMapper::class)] | ||
public string $name, | ||
#[MapName(SnakeCaseMapper::class)] | ||
public string $recordCompany, | ||
#[MapName(new ProvidedNameMapper('country field'))] | ||
public string $country, | ||
#[MapName(StudlyCaseMapper::class)] | ||
public string $cityName, | ||
#[MapName(LowerCaseMapper::class)] | ||
public string $addressLine1, | ||
#[MapName(UpperCaseMapper::class)] | ||
public string $addressLine2, | ||
) { | ||
} | ||
} | ||
``` | ||
```php | ||
[ | ||
'name' => 'Rick Astley', | ||
'record_company' => 'RCA Records', | ||
'country field' => 'Belgium', | ||
'CityName' => 'Antwerp', | ||
'addressline1' => 'some address line 1', | ||
'ADDRESSLINE2' => 'some address line 2', | ||
] | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this to a separate page in advanced-usage? And add links to it from this page and https://github.com/spatie/laravel-data/blob/b65bfc03dadb31605bbef4597c2917e2f901f2bc/docs/as-a-data-transfer-object/mapping-property-names.md#L94-L93
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I can do it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I decided to also add a link to the documentation page https://github.com/spatie/laravel-data/blob/main/docs/as-a-resource/mapping-property-names.md as it directly applies to it
- I hope I have correctly specified the page weight for the menu sorting.
- I don't know how correctly Google Translate translated the sentence into English.
src/Mappers/LowerCaseMapper.php
Outdated
@@ -0,0 +1,15 @@ | |||
<?php | |||
|
|||
declare(strict_types=1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not add strict types to Spatie packages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. My file templates use strict mode by default.
I'll remove that.
src/Mappers/UpperCaseMapper.php
Outdated
@@ -0,0 +1,15 @@ | |||
<?php | |||
|
|||
declare(strict_types=1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not add strict types to Spatie packages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
57f27fb
to
1f2bf3a
Compare
Thanks! |
In some projects there was a need to use such mappers and I created them in the application. Then I thought that they could be added to the package. Hope this helps :)
I also added information about available mappers with usage examples to the documentation page.